package com.bjpowernode.app.vo;

import org.springframework.context.annotation.Scope;

import java.util.List;


public class PageInfo<T> {
    //每页几行
    int pageSize;
    //总条数
    int countRows;
    //总页数
    int countPage;
    //当前页
    int currentPage;
    //首页
    int firstPage;
    //上一页
    int previousPage;
    //下一页
    int nextPage;
    //尾页
    int lastPage;
    //数据
    List<T> data;


    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCountRows() {
        return countRows;
    }

    public void setCountRows(int countRows) {
        this.countRows = countRows;
    }

    public int getCountPage() {
        return countPage;
    }

    public void setCountPage(int countPage) {
        this.countPage = countPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getFirstPage() {
        return firstPage;
    }

    public void setFirstPage(int firstPage) {
        this.firstPage = firstPage;
    }

    public int getPreviousPage() {
        return previousPage;
    }

    public void setPreviousPage(int previousPage) {
        this.previousPage = previousPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int getLastPage() {
        return lastPage;
    }

    public void setLastPage(int lastPage) {


        this.lastPage = lastPage;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }


    //业务逻辑方法
    //1:参数【只负责：用户输入的参数】
    //1-1:外部参数（通过配置得到的参数，application.properties）
    //1-2:用户输入的参数
    //2:返回什么给对法，如果是本类，那么直接void就可以了，因为本类已经进入了Spring容器
    public void execute(int countRows, int currentPage, List<T> data) {
        //总条数
        this.countRows = countRows;
        //总页数（countRows/）
        this.countPage = this.countRows % this.pageSize == 0 ? this.countRows / this.pageSize : this.countRows / this.pageSize + 1;
        //当前页
        this.currentPage = currentPage;
        //首页(1开始)
        this.firstPage = 1;

        if (this.currentPage > 1) {
            //上一页
            this.previousPage = this.currentPage - 1;
        } else {
            this.previousPage = 1;
        }

        if (this.currentPage < this.countPage) {
            //下一页
            this.nextPage = this.currentPage + 1;
        } else {
            this.nextPage = this.countPage;
        }
        //尾页
        this.lastPage = this.countPage;
        //数据
        this.data = data;
    }


}
